<!--申诉结果 申诉成功修改页面-->
<template>
  <el-dialog :title=title :close-on-click-modal="false" :visible.sync="viewShow" class="view">

    <!--运营评价-->
    <div v-if="(valueAppealContentVo.appealContent===1 || valueAppealContentVo.appealContent===3)">

      <span style="font-size: larger;margin-left: 70px">运营评价</span>

      <el-form ref="dataForm" :model="form"  style="margin-left: 70px;margin-top: 30px">
        <el-form-item label="运营评价总得分：" prop="values1">
          <span style="color: #0000cc">{{staffMemberEvaluateResultVo?staffMemberEvaluateResultVo.totalScore:""}}</span>
        </el-form-item>
        <el-form-item v-for="item in this.staffMemberEvaluateArr">
          <el-form-item :label=item.labelTitle prop="values1" label-width="78px">
            <el-input class="input" v-model="item.valueScore" type="number" max="5" min="1"></el-input>
            分
          </el-form-item>
          <!--    评分举例说明 -->
          <div v-if="item.valueDescribe" style="margin-top: 20px">
            <el-row>
              <el-col :span="12">
                <span>评分举例说明</span>
              </el-col>
              <el-col :span="12">
                <el-button @click="operationAction(item)">删除</el-button>
              </el-col>
            </el-row>
            <div style="margin-top: 10px">{{item.valueDescribe}}</div>
          </div>
          <!--      照片墙&ndash;&gt;-->
          <div class="imgContent" style="border-bottom: 1px solid #C5C5C5">
            <div class="imgitem" v-for="(imgUrl, index) in item.valueImg">
              <img :src="imgUrl" @click="setbig(imgUrl)">
              <div class="del"><i class="el-icon-circle-close-outline" @click="delImg(item.valueImg,index)"></i></div>
            </div>
          </div>
          <div v-if="(item.valueDescribe || item.valueImg)" style="border-bottom: 1px solid #C5C5C5"></div>
        </el-form-item>
      </el-form>

    </div>

    <!--    管家评价-->
    <div v-if="(valueAppealContentVo.appealContent===1 || valueAppealContentVo.appealContent===2)">
      <span style="font-size: larger;margin-left: 70px">管家评价</span>
      <el-form ref="dataForm" :model="form"  style="margin-left: 70px;margin-top: 30px">
          <el-form-item label="管家评价总得分：" prop="values1">
            <span style="color: #0000cc">{{valueCommentLogVo?valueCommentLogVo.totalScore:""}}</span>
          </el-form-item>
          <el-form-item v-for="item in valueCommentLogVoArr">
            <el-form-item :label=item.labelTitle prop="values1" label-width="78px">
              <el-input class="input" v-model="item.valueScore" type="number" max="5" min="1"></el-input>
              分
            </el-form-item>
            <!--    评分举例说明 -->
            <div v-if="item.valueDescribe" style="margin-top: 20px">
              <el-row>
                <el-col :span="12">
                  <span>评分举例说明</span>
                </el-col>
                <el-col :span="12">
                  <el-button @click="operationAction(item)">删除</el-button>
                </el-col>
              </el-row>
              <div style="margin-top: 10px">{{item.valueDescribe}}</div>
            </div>
            <!--      照片墙&ndash;&gt;-->
            <div class="imgContent" style="border-bottom: 1px solid #C5C5C5">
              <div class="imgitem" v-for="(imgUrl, index) in item.valueImg">
                <img :src="imgUrl" @click="setbig(imgUrl)">
                <div class="del"><i class="el-icon-circle-close-outline" @click="delImg(item.valueImg,index)"></i></div>
              </div>
            </div>
            <div v-if="(item.valueDescribe || item.valueImg)" style="border-bottom: 1px solid #C5C5C5"></div>
          </el-form-item>
      </el-form>
    </div>

    <el-form ref="dataForm" :model="form"  style="margin-left: 70px;margin-top: 70px">
      <el-form-item label="本季度提现服务系数：" prop="values1">
        <el-input class="input" v-model="valueAppealContentVo.ratio" type="number"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="viewShow = false">取消</el-button>
      <el-button @click="updataData">确定</el-button>
    </span>
    <bigimg :bigimgsrc="bigsrc" v-if="showbig" @hideimg="hidebig"></bigimg>
  </el-dialog>
</template>

<script>
    import bigimg from '@/components/bigimg/index'
    export default {
        name: "appealResultModify",
        components: {bigimg},

        data() {
            return {


                showbig: false,
                bigsrc:"",

                // 请求数据
                bindData:{},

                // 申诉内容
                valueAppealContentVo:{},

                staffMemberEvaluateArr:[],
                valueCommentLogVoArr:[],

                // 运营评价
                staffMemberEvaluateResultVo:{},
                // 管家评价
                valueCommentLogVo:{},

                viewShow: false,

                title: '申诉者考核成绩修改',
                form: {},
                id: '',


            };
        },
        methods: {

            init(dataObject) {

                this.viewShow = true

                this.bindData = {};
                this.staffMemberEvaluateResultVo = {};
                this.valueCommentLogVo = {};
                this.valueAppealContentVo = {};
                this.staffMemberEvaluateArr = [];
                this.valueCommentLogVoArr = [];

                this.bindData = dataObject

                this.valueAppealContentVo = dataObject;

                if (dataObject.staffMemberEvaluation) {
                    this.staffMemberEvaluateArr = this.getEvaluateArr(dataObject.staffMemberEvaluation);
                }
                if (dataObject.superiorEvaluation) {
                    this.valueCommentLogVoArr = this.getEvaluateArr(dataObject.superiorEvaluation);
                }

                this.staffMemberEvaluateResultVo = dataObject.staffMemberEvaluation;
                this.valueCommentLogVo = dataObject.superiorEvaluation;

            },


            //
            updataData() {

                let isreturn = false
                this.staffMemberEvaluateArr.map((item) => {
                    if (item.valueScore === ""&&!isreturn){

                        this.$message.error(item.labelTitle+"分数为空");
                        isreturn = true
                        return false
                    }
                })

                this.valueCommentLogVoArr.map((item) => {
                    if (item.valueScore === ""&&!isreturn){
                        this.$message.error(item.labelTitle+"分数为空");
                        isreturn = true
                        return false
                    }
                })

                if (this.valueAppealContentVo.ratio === "" && !isreturn) {
                    this.$message.error("提现服务系数不能为空");
                    isreturn = true
                }

                if(this.valueAppealContentVo.ratio){
                    if(this.valueAppealContentVo.ratio.toString().indexOf('.')>-1&&this.valueAppealContentVo.ratio.toString().split('.')[1].length>1){
                        this.$message({
                            message: '请保留一位小数',
                            type: "error"
                        })
                        isreturn = true
                        return false
                    }
                } else {
                    this.$message({
                        message: '请输入正确格式的数字',
                        type: "error"
                    })
                    isreturn = true
                    return false
                }

                this.staffMemberEvaluateArr.map((item) => {
                    if (!isreturn){
                        if (!this.isInteger(item.valueScore)) {
                            this.$message.error(item.labelTitle+"请输入整数");
                            isreturn = true
                            return false
                        } else {
                            if (item.valueScore > 5 || item.valueScore < 1) {
                                this.$message.error(item.labelTitle+"数值应该1-5");
                                isreturn = true
                                return false
                            }
                        }

                    }
                })

                this.valueCommentLogVoArr.map((item) => {
                    if (!isreturn){
                        if (!this.isInteger(item.valueScore)) {
                            this.$message.error(item.labelTitle+"请输入整数");
                            isreturn = true
                            return false
                        } else {
                            if (item.valueScore > 5 || item.valueScore < 1) {
                                this.$message.error(item.labelTitle+"数值应该1-5");
                                isreturn = true
                                return false
                            }
                        }

                    }
                })

              if(isreturn) {
                  return false
              }


                this.getEvaluateObject();

                this.$http({
                    url: this.$http.adornUrl("/value/valuecommentlog/update"),
                    method: "post",
                    data: this.$http.adornData(this.bindData)
                }).then(({ data }) => {

                    if (data && data.code === 0) {
                        this.$message.success("审核成功");
                        this.viewShow = false;
                        this.goBack();

                    } else {
                        this.$message({
                            message: data.msg,
                            type: "error"
                        })

                    }

                });

            },

            isInteger(obj){

                return typeof Number(obj) === 'number' && Number(obj)%1 === 0;
                // return  Math.round(obj) === obj   //是整数，则返回true，否则返回false

            },


            getEvaluateObject(){

                // 服务系数
                this.bindData.ratio = this.valueAppealContentVo.ratio;

                if (this.staffMemberEvaluateResultVo) {

                    // 1.运营评价
                    // 用户至上
                    this.bindData.staffMemberEvaluation.firstValueScore = this.staffMemberEvaluateArr[0].valueScore;
                    this.bindData.staffMemberEvaluation.firstValueDescribe = this.staffMemberEvaluateArr[0].valueDescribe;
                    this.bindData.staffMemberEvaluation.firstValueImg = this.staffMemberEvaluateArr[0].valueImg;

                    // 正直坦诚
                    this.bindData.staffMemberEvaluation.secondValueScore = this.staffMemberEvaluateArr[1].valueScore;
                    this.bindData.staffMemberEvaluation.secondValueDescribe = this.staffMemberEvaluateArr[1].valueDescribe;
                    this.bindData.staffMemberEvaluation.secondValueImg = this.staffMemberEvaluateArr[1].valueImg;

                    // 极致执行
                    this.bindData.staffMemberEvaluation.thirdValueScore = this.staffMemberEvaluateArr[2].valueScore;
                    this.bindData.staffMemberEvaluation.thirdValueDescribe = this.staffMemberEvaluateArr[2].valueDescribe;
                    this.bindData.staffMemberEvaluation.thirdValueImg = this.staffMemberEvaluateArr[2].valueImg;

                    // 精进创新
                    this.bindData.staffMemberEvaluation.fourthValueScore = this.staffMemberEvaluateArr[3].valueScore;
                    this.bindData.staffMemberEvaluation.fourthValueDescribe = this.staffMemberEvaluateArr[3].valueDescribe;
                    this.bindData.staffMemberEvaluation.fourthValueImg = this.staffMemberEvaluateArr[3].valueImg;

                    // 团结共赢
                    this.bindData.staffMemberEvaluation.fifthValueScore = this.staffMemberEvaluateArr[4].valueScore;
                    this.bindData.staffMemberEvaluation.fifthValueDescribe = this.staffMemberEvaluateArr[4].valueDescribe;
                    this.bindData.staffMemberEvaluation.fifthValueImg = this.staffMemberEvaluateArr[4].valueImg;

                }

                if (this.valueCommentLogVo) {

                    // 2.管家评价

                    // 用户至上
                    this.bindData.superiorEvaluation.firstValueScore = this.valueCommentLogVoArr[0].valueScore;
                    this.bindData.superiorEvaluation.firstValueDescribe = this.valueCommentLogVoArr[0].valueDescribe;
                    this.bindData.superiorEvaluation.firstValueImg = this.valueCommentLogVoArr[0].valueImg;

                    // 正直坦诚
                    this.bindData.superiorEvaluation.secondValueScore = this.valueCommentLogVoArr[1].valueScore;
                    this.bindData.superiorEvaluation.secondValueDescribe = this.valueCommentLogVoArr[1].valueDescribe;
                    this.bindData.superiorEvaluation.secondValueImg = this.valueCommentLogVoArr[1].valueImg;

                    // 极致执行
                    this.bindData.superiorEvaluation.thirdValueScore = this.valueCommentLogVoArr[2].valueScore;
                    this.bindData.superiorEvaluation.thirdValueDescribe = this.valueCommentLogVoArr[2].valueDescribe;
                    this.bindData.superiorEvaluation.thirdValueImg = this.valueCommentLogVoArr[2].valueImg;

                    // 精进创新
                    this.bindData.superiorEvaluation.fourthValueScore = this.valueCommentLogVoArr[3].valueScore;
                    this.bindData.superiorEvaluation.fourthValueDescribe = this.valueCommentLogVoArr[3].valueDescribe;
                    this.bindData.superiorEvaluation.fourthValueImg = this.valueCommentLogVoArr[3].valueImg;

                    // 团结共赢
                    this.bindData.superiorEvaluation.fifthValueScore = this.valueCommentLogVoArr[4].valueScore;
                    this.bindData.superiorEvaluation.fifthValueDescribe = this.valueCommentLogVoArr[4].valueDescribe;
                    this.bindData.superiorEvaluation.fifthValueImg = this.valueCommentLogVoArr[4].valueImg;

                }

            },

            getEvaluateArr(object){

                let labelTitleArr = ["用户至上  ","正直坦诚  ","极致执行  ","精进创新  ","团结共赢  "]
                let arr = []

                for (var i = 0;i < 5;i++) {

                    let item = {
                        labelTitle:labelTitleArr[i],
                        values1: [
                            {required: true, message: "分数不能为空", trigger: "blur"}
                        ],
                        // valueScore:"",
                        // valueDescribe:"",
                        // valueImg:[],
                    }
                    if (i === 0) {
                        item.valueScore = parseInt(object.firstValueScore);
                        item.valueDescribe = object.firstValueDescribe;
                        item.valueImg = object.firstValueImg;
                    } else if (i === 1) {
                        item.valueScore = parseInt(object.secondValueScore);
                        item.valueDescribe = object.secondValueDescribe;
                        item.valueImg = object.secondValueImg;

                    } else if (i === 2) {
                        item.valueScore = parseInt(object.thirdValueScore);
                        item.valueDescribe = object.thirdValueDescribe;
                        item.valueImg = object.thirdValueImg;

                    } else if (i === 3) {

                        item.valueScore = parseInt(object.fourthValueScore);
                        item.valueDescribe = object.fourthValueDescribe;
                        item.valueImg = object.fourthValueImg;
                    } else if (i === 4) {
                        item.valueScore = parseInt(object.fifthValueScore);
                        item.valueDescribe = object.fifthValueDescribe;
                        item.valueImg = object.fifthValueImg;
                    }
                    arr.push(item)

                }

                return arr;
            },

            operationAction(item) {
                item.valueDescribe = ""
            },

            delImg(imgArr,index) {
                imgArr.splice(index,1);
            },

            goBack () {
                this.$emit('goback')
            },

            setbig(imgUrl) {
                this.bigsrc = imgUrl
                this.showbig = true
            },
            hidebig() {
                this.showbig = false
            },
        },
    }
</script>

<style lang="scss" scoped>
  .input {
    width: 100px;
  }

  .imgContent {
    margin-top: 30px;
    display: flex;
    flex-wrap: wrap;
    .imgitem{
      position: relative;
      width: 120px;
      height: 120px;
      margin: 10px 20px;
      img{
        width:100%;
        height: 100%;
      }
      .del{
        font-size: 20px;
        position: absolute;
        top: -15px;
        right: -15px;
      }
    }
  }
</style>
